﻿using System;
using Foothill.DataAccess.Interface;
using Foothill.DataAccess.Repository;
using Foothill.Model;
using System.Collections.Generic;
using Foothill.DataAccess;

namespace Foothill.Filter.Test.TestUtilities
{
    internal class RepositoryUtility
    {
        private static IAdRepo _adRepo;
        private static IPhotoRepo _photoRepo;

        static RepositoryUtility()
        {
            _adRepo = new AdRepo();
            _photoRepo = new PhotoRepo();

            AdRepo.UseDatabase(DatabaseToUse.Test);
            PhotoRepo.UseDatabase(DatabaseToUse.Test);
        }

        internal static ForSaleAd InsertOnePostIntoRepositoryWithPhoto(ModelId modelId, MakeId makeId, VehicleCondition condition,
           int year, int mileAge, TransmissionType transmissionType, int price, ListingTypes listingType,
           City city, string phoneNumber, string email, DateTime lastEditDateTime)
        {
            ForSaleAd newAd = TestUtility.ConstructNewSaleAd(modelId, makeId, condition, year, mileAge, transmissionType, price, listingType, city, phoneNumber, email, lastEditDateTime);

            int newAdId = _adRepo.InsertNewForSaleAd(newAd);
            newAd.AdId = newAdId;

            UploadPhoto profilePhoto = TestUtility.ConstructProfilePhoto(newAdId);
            _photoRepo.InsertPhotos(new List<UploadPhoto>() { profilePhoto });

            return newAd;
        }
    }
}
